--长灯寒昼
local changdenghanzhou = fk.CreateSkill {
    name = "mcdh_changdenghanzhou",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

changdenghanzhou:addEffect(fk.AfterCardsMove,{
    can_trigger = function(self, event, target, player, data)
        local room =player.room
        if not player:hasSkill(self) then return false end
        if player:getHandcardNum() > player.hp  then return false end
        local targets = table.filter(room:getAlivePlayers(),function(p) return  p:getHandcardNum() >=  p.hp end)
        if #targets == 0 then return  false end
        self.cost_data = targets
        for _, move in ipairs(data) do
            if move.from == player then
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerHand then
                        return true
                    end
                end
            end
        end
    end,
    on_use =function(self, event, target, player, data)
        local room =player.room
        local cids = room:getNCards(5)
        room:moveCardTo(cids, Card.Processing, nil, fk.ReasonJustMove, self.name)
        local trueNames = {}
        for _, id in ipairs(cids) do
            table.insertIfNeed(trueNames,Fk:getCardById(id).trueName)
        end
        local targets = table.filter(room:getAlivePlayers(),function(p) return  p:getHandcardNum() >=  p.hp end)
        local to = room:askToChoosePlayers(player, {
            targets = targets, -- 必须是 ServerPlayer[]
            min_num = 1,
            max_num = 1,
            prompt = "#changdenghanzhou-choose",
            skill_name = self.name,
            cancelable = false
          })[1]
        trueNames =table.concat(trueNames,",")
        room:askForDiscard(to,1,1,true,self.name,false,"^("..trueNames..")")
        local cards = table.filter(cids, function(id) return room:getCardArea(id) == Card.Processing end)
        if #cards > 0 then
            room:moveCards({
                ids = cards,
                toArea = Card.DiscardPile,
                moveReason = fk.ReasonPutIntoDiscardPile,
            })
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_changdenghanzhou"] = "长灯寒昼",
    [":mcdh_changdenghanzhou"] = "当你失去手牌后，若你手牌数不大于体力值，你可以亮出牌堆顶五张牌，然后选择一名手牌数不小于体力值的角色，其弃置一张与这些牌牌名均不同的牌。",
    ["#changdenghanzhou-choose"] = "长灯寒昼：选择一名手牌数不小于体力值的角色，其弃置一张与这些牌牌名均不同的牌。",
}

return changdenghanzhou